package util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Locale;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;


public class ServerResponse implements Serializable
	{
	    public static Logger logger = LogManager.getLogger(ServerResponse.class);
	    
	    private Locale locale;
	    private String command;
	    private String destination;
	    private String responseCode;
	    private String responseMessage="";
	    private String target="";
	    private long time;
	   
	    private ArrayList<Object> data;
	    private ArrayList<Object> alternativedata;

	    /** Creates a new instance of ServerResponse */
	    public ServerResponse(String command, String destination, String responseCode)
	    {
	        this.command = command;
	        this.destination = destination;
	        this.responseCode = responseCode;
	    }

	    public ServerResponse(String command, String destination, String responseCode, long time)
	    {
	        this.command = command;
	        this.destination = destination;
	        this.responseCode = responseCode;
	        this.time = time;
	    }

	    public ServerResponse(String command, String destination, String responseCode, Locale locale)
	    {
	        this.command = command;
	        this.destination = destination;
	        this.responseCode = responseCode;
	        this.locale = locale;
	    }

	    public ServerResponse(String command, String destination, String responseCode, Locale locale, long time)
	    {
	        this.command = command;
	        this.destination = destination;
	        this.responseCode = responseCode;
	        this.locale = locale;
	        this.time = time;
	    }

	    

	    public void addData(Object data)
	    {
	        if(this.data == null)
	        {
	            this.data = new ArrayList<Object>();
	        }
	        this.data.add(data);
	    }

	   
	    
	   
	    @Override
	    public String toString()
	    {
	        String response = "";
	        response += "<ServerResponse>";
	        response += "<Command>" + this.command + "</Command>";
	        response += "<Destination>" + this.destination + "</Destination>";
	        response += "<ResponseMessage>" + this.responseMessage + "</ResponseMessage>";
	        response += "<ResponseCode>" + this.responseCode + "</ResponseCode>";
	        
	        if(this.locale != null)
	        {
	            response += "<Locale>" + this.locale + "</Locale>";
	        }
	        if(this.time != 0)
	        {
	            response += "<Time>" + this.time + "</Time>";
	        }
	        
	        if(this.data != null)
	        {
	            response += "<Result>";
	            for(int a = 0; a < this.data.size(); a++)
	            {
	                response += data.get(a).toString();
	            }
	            response += "</Result>";
	        }
	        response += "</ServerResponse>";

	        return response;
	    }

	    public String getResponseCode()
	    {
	        return this.responseCode;
	    }

	    public void setResponseCode(String responseCode)
	    {
	        this.responseCode = responseCode;
	    }

	   

	    public Locale getLocale()
	    {
	        if(locale == null)
	        {
	            return new Locale("it", "IT");
	        }
	        return locale;
	    }

	    public void setLocale(Locale locale)
	    {
	        this.locale = locale;
	    }

	    public long getTime()
	    {
	        return time;
	    }

	    public void setTime(long time)
	    {
	        this.time = time;
	    }

	    public String getDestination()
	    {
	        return destination;
	    }

	    public void setDestination(String destination)
	    {
	        this.destination = destination;
	    }

	    public ArrayList<Object> getData()
	    {
	        return data;
	    }
	    
	    public void setData(ArrayList<Object> data) {
			
			this.data=data;
		}
	    

	    public String getResponseMessage() {
	        return responseMessage;
	    }

	    public void setResponseMessage(String responseMessage) {
	        this.responseMessage = responseMessage;
	    }

		public String getTarget() {
			return target;
		}

		public void setTarget(String target) {
			this.target = target;
		}

		public ArrayList<Object> getAlternativedata() {
			return alternativedata;
		}

		public void setAlternativedata(ArrayList<Object> alternativedata) {
			this.alternativedata = alternativedata;
		}

		
	    
}
